<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>

</head>

<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="">首页</a>
                <a href="">新闻管理</a>
                <a>
                    <cite>新闻列表</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5">
                        <div class="layui-input-inline layui-show-xs-block">
                            <input type="text" id="newsAuthor" placeholder="请输入作者名称" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-input-inline layui-show-xs-block">
                            <input type="text" id="newsTitle" placeholder="请输入新闻标题" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-input-inline layui-show-xs-block" >
                            <input type="button" data-type="reload" class="layui-icon layui-btn"  id="select" value=&#xe615 />
                        </div>
                    </form>
                </div>
                <div class="layui-card-header">
                    <button class="layui-btn" onclick="xadmin.open('添加新闻','2news-add.html',800,600)"><i class="layui-icon"></i>添加</button>
                </div>
                <div class="layui-card-body ">
                    <table  cellpadding="0" cellspacing="0" class="layui-table"  id="test" lay-filter="test"></table>
                </div>
            </div>
        </div>
    </div>
</div>
</div>

</body>
<script>


    layui.use('table', function(){
        var form=layui.form;
        var table = layui.table;
        table.render({
            elem: '#test'
            ,url:'/hospital/api/back/news/limit'
            ,cellMinWidth:80
            ,parseData: function(res){ //res 即为原始返回的数据
                console.log(res)
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.page1.total ,//解析数据长度
                    "data": res.data.newsList//解析数据列表
                };
            }
            ,response: {
                statusCode: 0 //重新规定成功的状态码为 200，table 组件默认为 0
            }
            ,page: true //开启分页
            ,limit:5
            ,limits: [5, 10, 15,20] //自定义分页数据选项
            ,cols: [[
                {field:'newsId', width:'10%', title:'ID', sort: true}
                ,{field:'newsTitle', width:'20%', title: '新闻标题'}
                ,{field:'newsAuthor', width:'10%', title: '作者名称'}
                ,{field:'newsCreateTime', width:'20%', title: '创建时间',sort: true}
                ,{field:'newsModifyTime', title:'最新修改时间',width:'20%', sort: true }
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:'20%'}
            ]]
            ,id: 'testReload'
            ,page: true
        }); var $ = layui.$, active = {
            reload: function(){
                var newsAuthor=$("#newsAuthor").val();
                var newsTitle=$("#newsTitle").val();
                alert(newsAuthor)
                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        newsAuthor: newsAuthor,
                        newsTitle:newsTitle,
                    }
                }, 'data');
            }
        };
        $('#select').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        table.on('tool(test)', function(obj){
            var data=obj.data;
            if(obj.event === 'del'){
                layer.confirm('真的删除吗？', function(index){

                    $.ajax({
                        type:"get",
                        url:"/hospital/api/back/news/delete",
                        data:{"newsId":data.newsId},
                        dataType:"json",
                        success:function(data){
                            console.log(data);
                            layer.msg(data.msg, {
                                icon: 1
                            });
                            table.reload('testReload', {
                                page: {
                                    curr: 1 //重新从第 1 页开始
                                }
                            }, 'data');
                        }
                    });
                    layer.close(index);
                })
            }
        });
    })
</script>
<script type="text/html" id="barDemo">
    <a title="查看" class="layui-btn layui-btn-xs" lay-event="see"onclick="xadmin.open('查看','2news-view.html?id='+'{{d.newsId}}')" href="javascript:;">
        <i class="layui-icon">&#xe615;</i>
    </a>
    <a title="修改" class="layui-btn layui-btn-xs " lay-event="edit"onclick="xadmin.open('修改','2news-modify.html?id='+'{{d.newsId}}')" href="javascript:;">
        <i class="layui-icon">&#xe642;</i>
    </a>
    <a title="删除"class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon">&#xe640;</i></a>
</script>



</html>
